<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>角色管理</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css" >
	<link rel="stylesheet" href="https://cdn.staticfile.org/zTree.v3/3.5.40/css/zTreeStyle/zTreeStyle.css">
	<link rel="stylesheet" type="text/css" href="/static/m.css" >
	<!-- <link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/color.css" > -->
	<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/jquery-migrate/1.4.1/jquery-migrate.min.js"></script>
	<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
	<script src="/static/init.js?v=03311"></script>
	<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
	<script src="/static/searchEdit.js"></script>
	<!-- <script src="https://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script> -->
	<script src="https://cdn.staticfile.org/zTree.v3/3.5.40/js/jquery.ztree.all.min.js"></script>
	<script src="/static/validate.js"></script>
</head>
<body>
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center'" >
		<table id="gridList" ></table>
	</div>
</div>
<div id="searchbar">
<div class="maction">
		<a href="javascript:void(0)" id="addButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-plus mbutton'">新增</a>
		<a href="javascript:void(0)" id="editButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-pencil-alt mbutton'">编辑</a>
		<a href="javascript:void(0)" id="removeButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-trash-alt mbutton color-c5'">删除</a>
</div>
<!-- <form id="searchForm" >
	查询列:<input id="search-字段名" name="字段名" class="easyui-textbox" >
	查询列:<input id="search-字段名" name="字段名" class="easyui-textbox" >
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-search mbutton'" >查询</a>
</form> -->
</div>
<div id="dialog_1" >
<div class="easyui-layout" data-options="fit:true,border:false" style="">
	<div data-options="region:'north'" style="height:50px;overflow-x:hidden;">
		<form id="form-1" class="easyui-form container" data-options="novalidate:true">
			<input id="role_id" type="hidden" name="id">
			<div class="row">
				<div class="col-md-6"><input class="easyui-textbox" name="role_name" style="width:100%" data-options="label:'角色名称',required:true,validType:[],tipPosition:'bottom'"></div>
				<div class="col-md-6"><input class="easyui-textbox" name="remark" style="width:100%" data-options="label:'备注',validType:['maxLength[50]'],tipPosition:'bottom'"></div>
			</div>
		</form>
	</div>
	<div data-options="region:'south'" style="height:50px;overflow-x:hidden;">
		<div style="text-align:center;">
			<a href="javascript:void(0)" onclick="javascript:saveFuncSet()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
			<a href="javascript:void(0)" onclick="javascript:cancel()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-times mbutton'">取消</a>
		</div>
	</div>
	<div data-options="region:'center'" style="overflow-x:hidden;">
		<div class="easyui-layout" data-options="fit:true" style="">
			<div data-options="region:'west',collapsible:false" style="width:50%;">
				<div class="easyui-layout" data-options="fit:true" style="">
					<div data-options="region:'west',collapsible:false,title:'菜单可见授权'" style="width:50%;overflow-x:hidden; "><div id="menuTree1" class="ztree"></div></div>
					<div data-options="region:'center',collapsible:false,title:'URI访问授权'" style="overflow-x:hidden;"><div id="menuTree2" class="ztree"></div></div>
				</div>
			</div>
			<!-- <div data-options="region:'center',collapsible:false" style="width:50%;">
				<div class="easyui-layout" data-options="fit:true" style="">
					<div data-options="region:'west',collapsible:false,title:'资产类别授权'" style="width:50%;overflow-x:hidden;"><div id="menuTree3" class="ztree"></div></div>
					<div data-options="region:'center',collapsible:false,title:'使用地授权'" style="overflow-x:hidden;"><div id="menuTree4" class="ztree"></div></div>
				</div>
			</div> -->
		</div>
	</div>
</div>
	
</div>
<script>
var options={
		page_id:205,
		grid_id:"gridList",
		sqlname:"grid_205_sys_role",
		showCheckbox:false,
		rownumbers:false,
	};
	var menuRoot={ id:0, parent_id:null, open:true,nocheck:true};
	var ztreeSeting = {
			view: { showLine : false },
			callback:{
			},
			data: {
				key:{
					name:"name",//节点名称的属性名称
					checked:"checked"
				},
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "parent_id",
					rootPId: 0
				}
			},
			check: {
				enable: true,
				nocheckInherit: false
			},

	};

	//document ready
	$(function(){
		grid1=new uniontrip.datagrid.searchEdit(options);
		
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		$('#addButton').bind('click', function(){
			initmenu(0);
		});//新增行绑定事件
		$('#editButton').bind('click',function(){
			gridSelectRow(grid1.grid,function(row){
				initmenu(row.id);
			});
		});//编辑按钮绑定事件
		$('#removeButton').bind('click',function(){
			gridConfirm(grid1.grid,"是否确认删除",function(selectRow){
				$.post("/authenticated/role/delete",JSON.stringify({ids:selectRow.id}),function(result){
					if(result.success){
	    				grid1.load();
	    			}else{
	    				$.messager.alert("提示", "删除失败！<br>"+result.message);
	    			}
				});
			});
		});//删除行绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
		$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
		$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
	    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
	    //初始化搜索框
	    initsearch();
	    //initsessioninfo();
	    dialogHeight=windowHeight*0.6;
		$('#dialog_1').dialog({
			title:"新增角色",
			cls:"",
			/*width:'100%',
			height:dialogHeight,*/
			modal:true,
			closed:true,
			maximized:true,
			onClose:function(){
				//grid1.load();
			},
			/* buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					alert('ok');
				}
			},{
				text:'取消',
				handler:function(){
					alert('cancel');;
				}
			}] */
		});
	});

	function openDialog(id){
		$('#'+id).dialog('open');
	}
	function cancel(){
		$('#dialog_1').dialog('close');
	}

	function onDeleteRow(){
		gridConfirm(grid1.grid,"是否确认删除",deleteRow);
	}
	function deleteRow(row){
		$.post("/authenticated/xx/delete",JSON.stringify({"id":row.id}),function(result){
			if(result.status==200){
				$.messager.alert("提示", "删除成功！");
				grid1.load();
			}else{
				$.messager.alert("提示", "删除失败！<br>"+result.message);
			}
		});
	}


	/**
	 * 初始化搜索条件
	 */
	function initsearch(){
		/*$('#search-product_class_id').combotree({
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-product_class_id').combotree('clear');
				}
			}],
		    data:grid1.combotreeDatas.product_class_id
		});
		//初始化combobox例子
		$('#search-status').combobox({
			panelHeight:'auto',
			editable:false,
			valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(e){
					$(e.data.target).combobox('clear');
				}
			}],
		    data:grid1.comboboxDatas.status
		});*/
	}

	/**
	 * 菜单授权查询
	 */
	function initmenu(role_id){
		$.messager.progress({
			title:'数据加载中'
		});
		$.ajax({
			type: "post",
			contentType:"application/json",
			//async:false,
			url: "/authenticated/role/searchAuth",
			data:JSON.stringify({role_id:role_id}),
			dataType:"json",
			success: function(result){
				if(result.success){
					$.messager.progress('close');
					openDialog('dialog_1');
					if(role_id){//编辑
						var selected=grid1.grid.datagrid('getSelected');
						$('#form-1').form('load',selected);
					}else{
						$("#form-1").form('clear');
						//$("#role_id").val("");
					}
					zNodes1=result.data.authMenu;
					zNodes1.push(Object.assign({name:'系统模块'}, menuRoot));
					zTreeMenu1=$.fn.zTree.init($("#menuTree1"), ztreeSeting,zNodes1);
					zTreeMenu1.expandAll(true);
					
					zNodes2=result.data.authURI;
					zNodes2.push(Object.assign({name:'URI资源'}, menuRoot));
					zTreeMenu2=$.fn.zTree.init($("#menuTree2"), ztreeSeting,zNodes2);
					zTreeMenu2.expandAll(true);
					/* 
					zNodes3=result.data.authAssetClass;
					zNodes3.push(Object.assign({name:'资产类别'}, menuRoot));
					zTreeMenu3=$.fn.zTree.init($("#menuTree3"), ztreeSeting,zNodes3);
					zTreeMenu3.expandAll(true);
					
					zNodes4=result.data.authAssetPlace;
					zNodes4.push(Object.assign({name:'资产使用地'}, menuRoot));
					zTreeMenu4=$.fn.zTree.init($("#menuTree4"), ztreeSeting,zNodes4);
					zTreeMenu4.expandAll(true); */
				}else{
					$.messager.alert("提示", "查询失败！<br>"+result.message);
				}
			},
			error: function(){
				
			}
		});
	}

	/**
	 * 保存菜单权限
	 */
	function saveFuncSet(){
		if($("#form-1").form('enableValidation').form('validate')){
			var selected=grid1.grid.datagrid('getSelected');
			var role=$("#form-1").serializeObject();
			var postData={role:role};
			var nodes1 = zTreeMenu1.getCheckedNodes(true);
			var checkArray1=new Array();
			$.each(nodes1,function(i,v){
				checkArray1.push(v.id);
			});
			postData.authMenu=checkArray1;
			
			var nodes2 = zTreeMenu2.getCheckedNodes(true);
			var checkArray2=new Array();
			$.each(nodes2,function(i,v){
				checkArray2.push(v.id);
			});
			postData.authURI=checkArray2;
			
			/* 
			var nodes3 = zTreeMenu3.getCheckedNodes(true);
			var checkArray3=new Array();
			$.each(nodes3,function(i,v){
				checkArray3.push(v.id);
			});
			postData.authAssetClass=checkArray3;
			
			var nodes4 = zTreeMenu4.getCheckedNodes(true);
			var checkArray4=new Array();
			$.each(nodes4,function(i,v){
				checkArray4.push(v.id);
			});
			postData.authAssetPlace=checkArray4; */
			
			$.post("/authenticated/role/saveAuth",postData,function(result){
				if(result.success){
					info("保存成功！");
					grid1.load();
					cancel();
				}else{
					$.messager.alert("提示", "保存失败！<br>"+result.message);
				}
			});
		}
		
	}
</script>
</body>
</html>